package com.allchips.pin.config;

import com.allchips.pin.threads.EsSyncRunning;
import com.allchips.pin.threads.Original2StandardRunning;
import com.allchips.pin.threads.SpecialPunctuationRunning;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;

/**
 * @author gary
 * @date 2022年01月20日 11:40
 */
@EnableScheduling
@EnableAsync
@Configuration
@Slf4j
public class SchedulingConfig {

    @Resource
    Original2StandardRunning original2StandardRunning;

    @Resource
    SpecialPunctuationRunning specialPunctuationRunning;

    @Resource
    EsSyncRunning esSyncRunning;


    // 每1分钟执行一次更新ip地址
    @Scheduled(cron = "0/10 * * * * ?")
    public void replaceSpecialPunctuation() {
        //存在符号标准化，先标准化
        boolean run = specialPunctuationRunning.run();
        if (!run) {
            return;
        }
        //符号标准化完,标准化脚位
        run = original2StandardRunning.run();
        if (!run) {
            return;
        }
        //脚位标准化完，同步到es
        esSyncRunning.run();
    }

}
